package com.zhu.demodb.web;

import com.google.gson.Gson;
import com.zhu.demodb.entity.Man;
import com.zhu.demodb.service.ManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping(value = "/test")
public class TestController {
    private Gson gson = new Gson();

    @Autowired
    ManService service;

    @RequestMapping(value = "getman",method = RequestMethod.GET)
    public String getman(String id){
        Man man = service.getByid(id);
        return gson.toJson(man);
    }

    @RequestMapping(value = "create",method = RequestMethod.POST)
    public int createMan(@RequestBody Man man){
        int result = service.create(man.getName(),man.getAge());
        return result;
    }
}
